home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7983 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  868 b 

  1. Message-ID: <3124E619.DC3@peoplesoft.com>
  2. Date: Fri, 16 Feb 1996 12:16:25 -0800
  3. From: Randal Kuramoto <randal_kuramoto@peoplesoft.com>
  4. Organization: PeopleSoft
  5. X-Mailer: Mozilla 2.0b6a (WinNT; I)
  6. MIME-Version: 1.0
  7. Newsgroups: comp.lang.c++
  8. Subject: temporary is rvalue or lvalue?
  9. Content-Type: text/plain; charset=us-ascii
  10. Content-Transfer-Encoding: 7bit
  11. NNTP-Posting-Host: rkuramo2
  12. Path: ple-news-01.peoplesoft.com!
  13.  
  14. I thought a temporary was an l-value.  In the code below,
  15. is the application of the increment operator to the return value
  16. of Foo() in main() a compiler error?  I even tried to specify
  17. const on the return type of Foo().
  18.  
  19. struct X
  20. {
  21.     X() : m_i( 0 ) {};
  22.     X& operator++() { ++m_i; return( *this ); };
  23.     int m_i;
  24. };
  25.  
  26. const X Foo() { return X(); }
  27.  
  28. int main( int, char** )
  29. {
  30.     X x = ++Foo();    // BC4.52 and VC4.0 say it's okay
  31.     return( 0 );
  32. }
  33.